package kit.edu.lego.gruppe3.levels.treeArea.old;

import kit.edu.lego.gruppe3.levels.LevelSelector;
import kit.edu.lego.gruppe3.levels.LevelSolver;
import kit.edu.lego.gruppe3.levels.LevelSelector.Level;
import kit.edu.lego.gruppe3.sensors.Scanner;
import lejos.nxt.LCD;
import lejos.robotics.subsumption.Arbitrator;
import lejos.robotics.subsumption.Behavior;

public class TreeAreaSolver implements LevelSolver {
	
	private static TreeAreaState status = TreeAreaState.searchForCorner;
	public TreeAreaSolver(){
	
	}


	@Override
	public void start(){
		LevelSelector.getInstance().setCurrentLevel(Level.treeArea);
		Scanner.scan();
		setStatus(TreeAreaState.searchForTreeRight);
		Behavior cF = new CornerFinder();
		Behavior eF = new ExitFinder();
		Behavior lTF = new LeftTreeFinder();
		Behavior lTH = new LeftTreeHitter();
		Behavior lTC = new LeftTurnController();
		Behavior rTF = new RightTreeFinder();
		Behavior rTH = new RightTreeHitter();
		Behavior rTC = new RightTurnController();
		
		Behavior[] treeBehaviors = {eF, lTF, rTF, lTC, rTC, lTH, rTH, cF};
		
		Arbitrator arby = new Arbitrator(treeBehaviors, true);
		arby.start();
	}
	
	public static void setStatus(TreeAreaState status) {
		TreeAreaSolver.status = status;
	}

	public static TreeAreaState getStatus() {
		LCD.clear();
		LCD.drawString(status.toString(), 1, 1);
		LCD.refresh();
		return status;
	}
	
	private static boolean levelCleared = false;
	
	public static boolean isLevelCleared() {
		return levelCleared;
	}
	
	public static void setLevelCleared(boolean cleared){
		levelCleared = cleared;
	}
	
	public static void stop()
	{
		
	}
	@Override
	public String toString() {
		return "Treeareasolver";
	}

}
